/**
 * 获取当前运行的客户端(APP H5 小程序)
 * https://uniapp.dcloud.io/platform
 */
const getPlatform = () => {
  // #ifdef APP-PLUS
  const system = uni.getSystemInfoSync()
  if (system.platform == 'ios') {
       const platform = 5
  } else {
      const platform = 6
  }
  // #endif
  // #ifdef H5
  const platform = weixinOfficial() ? 2 : 3
  // #endif
  // #ifdef MP-WEIXIN
	// const platform = 0
	const platform = 1
  // #endif
  return platform
}

// 是否为微信公众号端
const weixinOfficial = () => {
  // #ifdef H5
  const ua = window.navigator.userAgent.toLowerCase()
  return String(ua.match(/MicroMessenger/i)) === 'micromessenger'
  // #endif
  return false
}

const platfrom = getPlatform()

export const isH5 = platfrom === 3
export const isApp = (platfrom === 5 || platfrom === 6)
export const isMpWeixin = platfrom === 1

// 是否为微信公众号端
// 相当于H5端运行在微信内置浏览器, 但是需要使用微信的jssdk所以要单独区分
export const isWeixinOfficial = platfrom === 2

export default platfrom
